<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@page import="java.io.*"%><%@page import="org.jdom.input.SAXBuilder,org.jdom.Document"%><%@page import="org.jdom.Element"%><%@page import="org.w3c.dom.NodeList"%>
<%
	System.out.println("-----------------滚石接受上行,解析上行-------------------");
	String syncDataSourceIp = request.getRemoteHost();
	String recvMsgType = "";
	String saveGwid = "";
	response.setContentType("text/plain");
	PrintWriter out1 = response.getWriter();

	InputStream in = request.getInputStream();
	StringBuffer provisionReq = new StringBuffer(512);
	byte[] buf = new byte[1024];
	int len = 0;
	try {
		while ((len = in.read(buf)) != -1) {
			provisionReq.append(new String(buf, 0, len, "UTF-8"));
		}
	} catch (IOException e) {
		e.printStackTrace();
	}
	in = new ByteArrayInputStream(provisionReq.toString().trim().getBytes("UTF-8"));
	SAXBuilder builder = new SAXBuilder();
	try {
		Document doc = builder.build(in);
		Element root = doc.getRootElement();
		String rootElementName = root.getName();
		//SpGetMoBean objMtBean = new SpGetMoBean();
		
		//解析节点
		String mobile = root.getChild("SRC_TERMID").getValue();          //手机号码
		String spcode = root.getChild("DST_SERVICECODE").getValue();
		String serviceType = root.getChild("SERVICEID").getValue();      //计费代码
		String linkid = root.getChild("TRANSACTIONID").getValue();
		String momsg = root.getChild("CONTENT").getValue();              //手机上行内容
		String feeType = root.getChild("DATA_TYPE").getValue();
		String fee=root.getChild("FEE_CODE").getValue();
		String province=root.getChild("PROVINCE").getValue();
		String date=root.getChild("SENDTIME").getValue();
		//把解析后的数据保存下来
		/*
		objMtBean.setGatewayId("");
		objMtBean.setUserPhone(mobile);
		objMtBean.setSpCode(spcode);
		objMtBean.setMsgId("");
		objMtBean.setMid("");
		objMtBean.setLinkId(linkid);
		objMtBean.setMoBody(momsg);
		if(Integer.parseInt(fee)==200||Integer.parseInt(fee)==100){
			objMtBean.setMoType("2");
		}
		else{
			objMtBean.setMoType("1");
		}
		
		objMtBean.setChannel("");
		objMtBean.setProductId("");
		objMtBean.setFee(fee);
		objMtBean.setSrvCode(serviceType);
		objMtBean.setCreateTime(DateUtil.getNow_Timestamp().toString());
		objMtBean.setSpFlat("");
		objMtBean.setRegion("");
		objMtBean.setFeeId("");
		objMtBean.setAreaId(province);
		objMtBean.setFlowId("");
		objMtBean.setIsUnionSpNo("");
		objMtBean.setRemark("");*/

		//把得到的上行插入到上行临时表中
		//SpGetMoService.getInstance().addSpAirGetMo(objMtBean);
		//String gatewayId = null;
		
		System.out.println("*********");
		int provinceId = BillingUtil.getProvinceId(mobile);
		System.out.println(provinceId);
		StringBuilder sb = new StringBuilder();
	    sb.append("'");
	    
	    sb.append(provinceId);
	    
	    
	    sb.append("',");
	    sb.append("'");
	    sb.append(mobile);
	    sb.append("',");
	    sb.append("'");
	    sb.append(spcode);
	    sb.append("',");
	    sb.append("");
	    sb.append("getDate()");
	    sb.append(",");
	    sb.append("'");
	    sb.append("msgid");
	    sb.append("',");
	    sb.append("'");
	    sb.append("mid");
	    sb.append("',");
	    sb.append("'");
	    sb.append("1");//cardtype
	    sb.append("',");
	    sb.append("'");
	    sb.append("01");//channel
	    sb.append("',");
	    sb.append("'");
	    sb.append("101");//prdid
	    sb.append("',");
	    sb.append("'");
	    sb.append("010");//telid
	    sb.append("',");
	    sb.append("'");
	    sb.append(linkid);//linkid
	    sb.append("',");
	    sb.append("'");
	    sb.append(momsg);//上行内容
	    sb.append("'");
	    sb.append(",");
	    sb.append(provinceId);
	    
	    SqlUtil.executeUpdate("insert into "+BillingUtil.getRecvDay()+"(areaid,org,dest,tm,msgid,mid,cardtype,channel,prdid,teleid,linkid,body,province) values("+sb.toString()+")",DbOperation.DB_STAT);
		
		if(momsg!=null&&momsg.equals("11")&&spcode!=null&&spcode.equals("106699679")) {
			StringBuilder mo = new StringBuilder("http://121.14.118.209:9527/sms/kongjian/kongjianMo.jsp?userPhone=");
			mo.append(mobile);
			mo.append("&spNo=");
			mo.append(spcode);
			mo.append("&linkId=");
			mo.append(linkid);
			mo.append("&mo=");
			mo.append(momsg);
			mo.append("&date=");
			mo.append(date);
			System.out.println(mo.toString());
			System.out.println(HttpUtil.getHtmlSource(mo.toString(),"UTF-8"));
			
		}
		
		String xmlStr="<?xml version=\"1.0\" encoding=\"gb2312\" ?><MASP><RESULT>200</RESULT><CONTENT></CONTENT></MASP>";
		out1.print(xmlStr);
		out1.flush();
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			out1.close();
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
%>

